x = 10
repeat
  print(x)
  x = x - 1
until x <= 0


--[[
for var = bigin, finish, setp do
end

1. var 从 bigin 变化到 finish 以 setp 作为步长递增
2. begin ,finish setp 三个表达式只会在循环开始时执行一次
3. setp 可选，默认为1
4. 变量 var 的作用域仅在for 循环内
循环过程中不要改变控制变量的值，那样会带来不可预知的影响 
]]--
print("=========================")
for i = 1, 5 do
  print(i)
end
print("=========================")

for i = 1, 10, 2 do
  print(i)
end
print("=========================")
for i = 10, 1, -1 do
  print(i)
end
print("=========================")
-- for 泛型，通过迭代器 iterator 遍历所有值
local a = {"a", "b", "c", "d"}
for i, v in ipairs(a) do
  print("index:", i, "value:", v)
end
print("=========================")
-- 将一个名称转换成它在一周中的位置
local revDays = {
  ["Sunday"] = 1,
  ["Monday"] = 2,
  ["Tuesday"] = 3,
  ["Wednesday"] = 4,
  ["Thursday"] = 5,
  ["Friday"] = 6,
  ["Saturday"] = 7
}
local x = "Tuesday"
print(revDays[x])  -->3
print("=========================")

-- 不用手动声明，通过 table 自动构造出这个逆向 table
local days = {
  "Monday", "Tuesday", "Wednesday", "Thursday",
  "Friday", "Saturday","Sunday"
}
local revDays = {}

for k, v in ipairs(days) do
  revDays[v] = k
end

print(revDays['Friday'])